<template>
  <!-- 暂时废弃了这个组件 -->
  <scroll-view class="card-list" :scroll-y="true">
    <!-- 双击触发事件 -->
    <button
      class="more"
      size="mini"
      @tap.stop="handleExit"
      style="position: fixed; bottom: 20px; right: 20px; z-index: 999"
      >exit</button
    >
    <template v-if="project_list.length > 0">
      <u-collapse
        :border="false"
        align="left"
        @open="onOpenCollapse($event)"
        :value="collapseValues"
        ref="collapseRef"
      >
        <u-collapse-item
          v-for="(project_item, index) in project_list"
          :key="project_item.id"
          :title="`Project ID:${project_item.project_number}${
            project_item.group_name ? '-' + project_item.group_name : ''
          }`"
          :name="index"
        >
          <view
            class="card-item"
            v-for="item in project_item.work"
            :key="item.id"
            @tap.stop="navigateTo(`${COUNRSEPATH}?id=${item.source_uniqid}`)"
          >
            <view class="top">
              <text class="order-number">{{ item.source_uniqid }}</text>
              <text>{{ item.department_type }}</text>
            </view>
            <view class="middle">
              <scroll-view class="img-list">
                <template v-if="item.imgs">
                  <view class="img-item" v-for="Imgitem in item.imgs.slice(0, 3)" :key="Imgitem">
                    <img :src="Imgitem" alt="" />
                  </view>
                </template>
              </scroll-view>
              <text class="img-number">{{ $t('me.total') + ':' + item.request_count }}</text>
            </view>
            <view class="bottom">
              <view class="more" @tap.stop="navigateTo(`${COUNRSEPATH}?id=${item.source_uniqid}`)">
                <u-icon name="more-circle" color="#999" size="28" />
                <text style="margin-left: 8rpx">{{ $t('me.more') }}</text>
              </view>

              <view class="button-list">
                <view
                  class="bottom"
                  :class="item.is_have_qc == 0 ? 'view-qc-report' : ''"
                  @tap.stop="onToQCReport(item.source_uniqid, item.is_have_qc)"
                  >{{ $t('me.viewQCReport') }}
                </view>
                <view
                  class="bottom satisfaction-rating"
                  @tap.stop="handleNavigate(item.id, item)"
                  >{{ $t('me.satisfactionRating') }}</view
                >
              </view>
            </view>
          </view>
        </u-collapse-item>
      </u-collapse>
    </template>
    <template v-else> <NoDataTitle /> </template>
  </scroll-view>
</template>

<script>
import NoDataTitle from '@/components/sys/NoDataTitle.vue'
import { QCREPORTPATH, COUNRSEPATH, LOGINPATCH } from '@/constants/router/subPackages'
import storage from '@/utils/storage'
export default {
  data() {
    return {
      COUNRSEPATH,
      collapseValues: []
    }
  },
  name: 'ProjectList',
  props: {
    project_list: {
      type: Array,
      default: () => []
    },
    handleNavigate: {
      type: Function,
      default: () => {}
    },
    navigateTo: {
      type: Function,
      default: () => {}
    }
  },
  methods: {
    handleExit() {
      uni.showModal({
        title: 'exit',
        content: 'Are you sure you want to exit?',
        success: (res) => {
          storage.clear()
          if (res.confirm) {
            uni.reLaunch({
              url: LOGINPATCH
            })
          }
        }
      })
    },
    onCloseAllCollapse() {
      this.collapseValues = []
      this.$nextTick(() => {
        this.$refs.collapseRef.init()
      })
    },
    onToQCReport(source_uniqid, is_have_qc) {
      if (is_have_qc == 0) return
      uni.navigateTo({
        url: `${QCREPORTPATH}?source_uniqid=${source_uniqid}&type=saleOrder`
      })
    },
    onOpenCollapse(project_index) {
      const item = this.project_list[project_index]
      this.$emit('projectListToMeParams', { project_index, item })
    }
  },
  components: { NoDataTitle }
}
</script>
<style lang="scss" scoped>
@import '../scss/index.scss';
</style>
